//
//  AppraiseViewController.m
//  PYWGetColor
//
//  Created by appleLJ on 2018/6/15.
//  Copyright © 2018年 dwj. All rights reserved.
//

#import "AppraiseViewController.h"
#import "StarView.h"
#import "AppraiseCollectionViewCell.h"
#import "SelectPicCollectionViewCell.h"
#import "ZYQAssetPickerController.h"

@interface AppraiseViewController ()<UICollectionViewDelegate,UICollectionViewDataSource,ZYQAssetPickerControllerDelegate,UINavigationControllerDelegate,delegateMarkView,UITextViewDelegate>

@property(nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong) UIView *headerView;
@property(nonatomic,strong) UIView *footerView;
@property(nonatomic,strong) UIView *bgView;
@property(nonatomic,strong) StarView *startView;
@property(nonatomic,strong) UICollectionView *collectionView;
@property(nonatomic,strong) UICollectionView *picCollectionView;//图片coll

@property(nonatomic,strong) NSMutableArray *dataArray;
@property(nonatomic,strong) NSMutableArray *picDataArray;
@property(nonatomic,strong) UIImageView *headImgView; // 头像
@property(nonatomic,strong) UILabel *nickNameLabel; // 用户名
@property(nonatomic,strong) UILabel *deallNumberLabel; // 成交数量
@property(nonatomic,strong) UILabel *scoreLabel; // 分数
@property(nonatomic,strong) UILabel *moneyLabel; // 金额
@property(nonatomic,strong) NSString *starnum; // 星星数量
@property(nonatomic,strong) UITextView *textView; //评论内容

@end

@implementation AppraiseViewController
/**
 评价页信息
 参数名    必选    类型    说明
 uid    是    string    用户id
 token    是    string    秘钥
 orderid    是    int    被评价的订单id
 */
- (void)comentInfomation {
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=commentinfo" parameters:@{@"uid":[UserModel sharedInstanced].userId,@"token":[UserModel sharedInstanced].token,@"orderid":self.mineOrderModelList.order_id} progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
             [self.headImgView sd_setImageWithURL:[NSURL URLWithString:responseObject[@"data"][@"avatar"]]];
            self.nickNameLabel.text = responseObject[@"data"][@"skill_title"];
            self.deallNumberLabel.text = [NSString stringWithFormat:@"成交数量:%@",responseObject[@"data"][@"count"]];
            self.scoreLabel.text = responseObject[@"data"][@"star"];
            self.moneyLabel.text = responseObject[@"data"][@"amount"];
            NSArray *bqArray = responseObject[@"data"][@"comment_label"];
            for (int i = 0; i < bqArray.count; i++) {
                self.dataArray[i][@"title"] = bqArray[i][@"name"];
            }
            [self.collectionView reloadData];
        }else{
            ShowMessage(@"操作失败");
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self showError:error];
    }];
}

/**
 参数名    必选    类型    说明
 uid    是    int    uid
 token    是    string    秘钥
 orderid    是    string    被评价的订单
 starnum    是    string    星星数
 content    是    string    评论内容
 comment_label_id    是    string    评论标签id(多个用逗号分隔)
 comment_pic[]    是    file    评论图片(多图上传)
 */
- (void)AddData{
//    if (_picDataArray == nil || [_picDataArray isKindOfClass:[NSNull class]] || _picDataArray.count == 0){
//
//        ShowMessage(@"请选择文件图片");
//        return;
//    }
    //    if (_dataArray.count <= 0 ) {
    //        ShowMessage(@"请选择文件");
    //    }
    //    if (_dataImageArray.count <= 0 ) {
    //        ShowMessage(@"请选择文件");
    //    }
    [self showprogressHUD];
    NSMutableArray *mArray = @[].mutableCopy;
    for (NSDictionary *dic in self.dataArray) {
        if ([dic[@"value"] isEqualToString:@"1"]) {
            [mArray addObject:dic[@"id"]];
        }
    }
    NSString *labelIdStr = [mArray componentsJoinedByString:@","];
    NSDictionary *parameters = @{@"uid":[UserModel sharedInstanced].userId,@"token":[UserModel sharedInstanced].token,@"orderid":self.mineOrderModelList.order_id,@"starnum":self.starnum,@"content":self.textView.text,@"comment_label_id":labelIdStr};
    
    [[AFAppDotNetAPIClient sharedClient] POST:@"interface.php?m=submitcomment" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        for (UIImage *img in self.picDataArray) {
            NSData *data = UIImageJPEGRepresentation(img, .2);
            NSString *imgName = [NSString stringWithFormat:@"%ld.jpg",(unsigned long)[NSDate date].timeIntervalSince1970];
            [formData appendPartWithFileData:data name:@"comment_pic[]" fileName:imgName mimeType:@"image/jpeg"];
        }
    } progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        [self hiddenProgressHUD];
        if ([responseObject[@"error_code"] isEqualToString:@"0"]) {
            [self.view makeToast:@"发布成功" duration:1 position:CSToastPositionCenter title:nil image:nil style:nil completion:^(BOOL didTap) {
                [self.navigationController popViewControllerAnimated:YES];
            }];
        }
        ShowMessage(responseObject[@"data"][@"prompt"]);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        [self hiddenProgressHUD];
        [self showError:error];
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    self.navigationItem.title = @"评价";
    [self.view addSubview:self.tableView];
    [self comentInfomation];
    self.starnum = @"5.0";
}
#pragma mark -- event
- (void)commitBtnAction{
    NSLog(@"提交");
    [self AddData];
}
//选择图片
- (void)selectPictures{
    ZYQAssetPickerController *picker = [[ZYQAssetPickerController alloc] init];
    picker.maximumNumberOfSelection = 9-self.picDataArray.count;
    picker.assetsFilter = [ALAssetsFilter allPhotos];
    picker.showEmptyGroups = NO;
    picker.delegate = self;
    picker.selectionFilter = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings){
        if ([[(ALAsset *)evaluatedObject valueForProperty:ALAssetPropertyType] isEqual:ALAssetTypeVideo]){
            NSTimeInterval duration = [[(ALAsset *)evaluatedObject valueForProperty:ALAssetPropertyDuration] doubleValue];
            return duration >= 5;
        } else {
            return YES;
        }
    }];
    
    [self presentViewController:picker animated:YES completion:NULL];
}

#pragma mark -- init
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - SafeAreaTopHeight - SafeAreaBottomHeight) style:UITableViewStylePlain];
        _tableView.backgroundColor = getColor(@"f4f4f4");
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.tableHeaderView = self.headerView;
        _tableView.tableFooterView = self.footerView;
    }
    return _tableView;
}

- (UIView *)headerView{
    if (!_headerView) {
        _headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - SafeAreaTopHeight - SafeAreaBottomHeight)];
        _headerView.backgroundColor = getColor(@"f4f4f4");
        
        //提交评论按钮
        UIButton *commitButton = [[UIButton alloc] init];
        commitButton.titleLabel.font = DEF_FontSize_16;
        commitButton.titleLabel.textAlignment = NSTextAlignmentCenter;
        [commitButton setTitle:@"提交评论" forState:UIControlStateNormal];
        [commitButton setTitleColor:getColor(whiteColor) forState:UIControlStateNormal];
        commitButton.backgroundColor = getColor(@"3eceb2");
        commitButton.layer.cornerRadius = 3;
        commitButton.layer.masksToBounds = YES;
        [commitButton addTarget:self action:@selector(commitBtnAction) forControlEvents:UIControlEventTouchUpInside];
        
        [_headerView addSubview:self.bgView];
        [_headerView addSubview:commitButton];
        //约束
        [commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(_headerView).offset(-20 / HEIGHT_6S_SCALE);
            make.left.equalTo(_headerView).offset(10 / WIDTH_6S_SCALE);
            make.right.equalTo(_headerView).offset(-10 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
        }];
        [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(_headerView).offset(10 / HEIGHT_6S_SCALE);
            make.right.equalTo(_headerView).offset(-10 / HEIGHT_6S_SCALE);
            make.bottom.equalTo(commitButton.mas_top).offset(-16 / HEIGHT_6S_SCALE);
        }];
    }
    return _headerView;
}
- (UIView *)footerView{
    if (!_footerView) {
        _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0.01)];
    }
    return _footerView;
}
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.layer.cornerRadius = 3;
        _bgView.layer.masksToBounds = YES;
        _bgView.backgroundColor = getColor(whiteColor);
        //头像
        UIImageView *headImgView = [[UIImageView alloc] init];
        headImgView.image = [UIImage imageNamed:@"list_btn_pic.1"];
        self.headImgView = headImgView;
        //姓名
        UILabel *nickNameLabel = [[UILabel alloc] init];
        nickNameLabel.font = DEF_FontSize_14;
        nickNameLabel.textAlignment = NSTextAlignmentLeft;
        nickNameLabel.textColor = getColor(blackColor);
        nickNameLabel.text = @"黄师傅(浑南长白苏家屯)";
        self.nickNameLabel = nickNameLabel;
        //成交数量
        UILabel *deallNumberLabel = [[UILabel alloc] init];
        deallNumberLabel.font = DEF_FontSize_12;
        deallNumberLabel.textAlignment = NSTextAlignmentLeft;
        deallNumberLabel.textColor = getColor(blackColor);
        deallNumberLabel.text = @"成交数量：120";
        self.deallNumberLabel = deallNumberLabel;
        //星星分数
        UIImageView *startImgView = [[UIImageView alloc] init];
        startImgView.image = [UIImage imageNamed:@"lefebar_xing1"];
        //分数
        UILabel *scoreLabel = [[UILabel alloc] init];
        scoreLabel.font = DEF_FontSize_12;
        scoreLabel.textAlignment = NSTextAlignmentLeft;
        scoreLabel.textColor = getColor(blackColor);
        scoreLabel.text = @"5.0";
        self.scoreLabel = scoreLabel;
        //线1
        UIView *lineView1 = [[UIView alloc] init];
        lineView1.backgroundColor = getColor(dividerColor);
        //金额
        UILabel *moneyLabel = [[UILabel alloc] init];
        moneyLabel.font = DEF_FontSize_26;
        moneyLabel.textAlignment = NSTextAlignmentCenter;
        moneyLabel.textColor = getColor(blackColor);
//        moneyLabel.text = @"120.00";
        self.moneyLabel = moneyLabel;
        //金额单位
        UILabel *unitLabel = [[UILabel alloc] init];
        unitLabel.font = DEF_FontSize_10;
        unitLabel.textAlignment = NSTextAlignmentLeft;
        unitLabel.textColor = getColor(blackColor);
        unitLabel.text = @"元";
        //线2
        UIView *lineView2 = [[UIView alloc] init];
        lineView2.backgroundColor = getColor(dividerColor);
        //星星评分
        //非常满意
        UILabel *descriptionLabel = [[UILabel alloc] init];
        descriptionLabel.font = DEF_FontSize_13;
        descriptionLabel.textAlignment = NSTextAlignmentCenter;
        descriptionLabel.textColor = getColor(@"F08D40");
        descriptionLabel.text = @"非常满意，无可挑剔";
        //夸夸师傅
        UILabel *praiseLabel = [[UILabel alloc] init];
        praiseLabel.font = DEF_FontSize_12;
        praiseLabel.textAlignment = NSTextAlignmentCenter;
        praiseLabel.textColor = getColor(blackColor);
        praiseLabel.text = @"夸夸师傅吧";
        //背景view
        UIView *textBgView = [[UIView alloc] init];
        textBgView.backgroundColor = getColor(@"f4f4f4");
        textBgView.layer.cornerRadius = 3;
        textBgView.layer.masksToBounds = YES;
        //其他想说的
        UITextView *textView = [[UITextView alloc] init];
        textView.font = DEF_FontSize_14;
        textView.textColor = getColor(textColor);
        textView.textAlignment = NSTextAlignmentLeft;
        textView.backgroundColor = getColor(@"f4f4f4");
        textView.text = @"其他想说的";
        textView.delegate = self;
        self.textView = textView;
        //线3
        UIView *lineView3 = [[UIView alloc] init];
        lineView3.backgroundColor = getColor(dividerColor);
        //添加控件
        [_bgView addSubview:headImgView];
        [_bgView addSubview:nickNameLabel];
        [_bgView addSubview:deallNumberLabel];
        [_bgView addSubview:startImgView];
        [_bgView addSubview:scoreLabel];
        [_bgView addSubview:lineView1];
        [_bgView addSubview:moneyLabel];
        [_bgView addSubview:unitLabel];
        [_bgView addSubview:lineView2];
        [_bgView addSubview:self.startView];
        [_bgView addSubview:descriptionLabel];
        [_bgView addSubview:praiseLabel];
        [_bgView addSubview:self.collectionView];
        [_bgView addSubview:textBgView];
        [_bgView addSubview:textView];
        [_bgView addSubview:lineView3];
        [_bgView addSubview:self.picCollectionView];
        
        //约束
        [headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_bgView).offset(20 / HEIGHT_6S_SCALE);
            make.left.equalTo(_bgView).offset(26 / WIDTH_6S_SCALE);
            make.height.width.mas_equalTo(60 / WIDTH_6S_SCALE);
            headImgView.layer.cornerRadius = 60 / 2 / WIDTH_6S_SCALE;
            headImgView.layer.masksToBounds = YES;
        }];
        [nickNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(headImgView.mas_right).offset(10 / WIDTH_6S_SCALE);
            make.centerY.equalTo(headImgView).offset(-6 / HEIGHT_6S_SCALE);
        }];
        [deallNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(nickNameLabel);
            make.top.equalTo(nickNameLabel.mas_bottom).offset(6 / HEIGHT_6S_SCALE);
        }];
        [startImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(deallNumberLabel.mas_right).offset(6 / WIDTH_6S_SCALE);
            make.centerY.equalTo(deallNumberLabel);
            make.width.height.mas_equalTo(12 / WIDTH_6S_SCALE);
        }];
        [scoreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(startImgView.mas_right).offset(2 / WIDTH_6S_SCALE);
            make.centerY.equalTo(deallNumberLabel);
        }];
        [lineView1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(_bgView);
            make.top.equalTo(headImgView.mas_bottom).offset(16 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(0.5);
        }];
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView1.mas_bottom).offset(20 / HEIGHT_6S_SCALE);
            make.centerX.equalTo(_bgView);
        }];
        [unitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(moneyLabel.mas_right);
            make.centerY.equalTo(moneyLabel).offset(6 / HEIGHT_6S_SCALE);
        }];
        [lineView2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.height.equalTo(lineView1);
            make.top.equalTo(moneyLabel.mas_bottom).offset(20 / HEIGHT_6S_SCALE);
        }];
        [descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.startView.mas_bottom).offset(16 / HEIGHT_6S_SCALE);
            make.centerX.equalTo(self.startView);
        }];
        [praiseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(descriptionLabel.mas_bottom).offset(18 / HEIGHT_6S_SCALE);
            make.centerX.equalTo(descriptionLabel);
        }];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(_bgView).offset(30 / WIDTH_6S_SCALE);
            make.right.equalTo(_bgView).offset(-30 / WIDTH_6S_SCALE);
            make.top.equalTo(praiseLabel.mas_bottom).offset(14 / HEIGHT_6S_SCALE);
            make.height.mas_equalTo(70 / HEIGHT_6S_SCALE);
        }];
        [textBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.collectionView.mas_bottom).offset(20 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(self.collectionView);
            make.height.mas_equalTo(120 / HEIGHT_6S_SCALE);
        }];
        [textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(textBgView);
            make.left.equalTo(textBgView).offset(4 / WIDTH_6S_SCALE);
            make.right.equalTo(textBgView).offset(-4 / WIDTH_6S_SCALE);
            make.height.mas_equalTo(70 / HEIGHT_6S_SCALE);
        }];
        [lineView3 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(textView);
            make.top.equalTo(textView.mas_bottom);
            make.height.mas_equalTo(1);
        }];
        [self.picCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lineView3.mas_bottom).offset(2 / HEIGHT_6S_SCALE);
            make.left.right.equalTo(textView);
            make.height.mas_equalTo(40 / HEIGHT_6S_SCALE);
        }];
    }
    return _bgView;
}
- (StarView *)startView{
    if (!_startView) {
        _startView = [[StarView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH * 0.25 - 10 / WIDTH_6S_SCALE , 190 / HEIGHT_6S_SCALE, SCREEN_WIDTH * 0.5, 24 / HEIGHT_6S_SCALE)];
        _startView.delegate = self;
        [_startView showMarkWithStar:5.0];
    }
    return _startView;
}
- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake((SCREEN_WIDTH - 80 / WIDTH_6S_SCALE - 10) / 2,30 / HEIGHT_6S_SCALE);
        flowLayout.minimumLineSpacing = 10;//横向距离
        flowLayout.minimumInteritemSpacing = 2;//竖向距离
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 10, 10, 10) collectionViewLayout:flowLayout];
        _collectionView.backgroundColor = getColor(whiteColor);
        _collectionView.bounces = YES;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_collectionView registerClass:[AppraiseCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([AppraiseCollectionViewCell class])];
    }
    return _collectionView;
}
- (UICollectionView *)picCollectionView{
    if (!_picCollectionView) {
        UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
        flowLayout.itemSize = CGSizeMake(40/WIDTH_5S_SCALE, 40/WIDTH_5S_SCALE);
        flowLayout.minimumLineSpacing = 4;//横向距离
        flowLayout.minimumInteritemSpacing = 0;//竖向距离
        flowLayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _picCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(10, 10, 10, 10) collectionViewLayout:flowLayout];
        _picCollectionView.backgroundColor = getColor(@"f4f4f4");
        _picCollectionView.bounces = YES;
        _picCollectionView.delegate = self;
        _picCollectionView.dataSource = self;
        _picCollectionView.showsVerticalScrollIndicator = NO;
        _picCollectionView.showsHorizontalScrollIndicator = NO;
        _picCollectionView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        [_picCollectionView registerClass:[SelectPicCollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([SelectPicCollectionViewCell class])];
    }
    return _picCollectionView;
}
#pragma mark -- delegateMarkView
- (void)getMark:(CGFloat)mark{
    NSLog(@"%f",mark);
//    self.scoreLabel.text = [NSString stringWithFormat:@"%0.1f",mark];
    self.starnum = [NSString stringWithFormat:@"%0.1f",mark];
}
#pragma mark -- UICollectionViewDelegate,UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if (collectionView == self.collectionView) {
        return self.dataArray.count;
    }else{
        return self.picDataArray.count + 1;
    }
}
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.collectionView) {
        AppraiseCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([AppraiseCollectionViewCell class]) forIndexPath:indexPath];
        cell.model = self.dataArray[indexPath.row];
        return cell;
    }else{
        SelectPicCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([SelectPicCollectionViewCell class]) forIndexPath:indexPath];
        cell.deleteHandle = ^(){
            [self.picDataArray removeObjectAtIndex:indexPath.row];
            [collectionView reloadData];
        };
        if (indexPath.row < self.picDataArray.count) {
            cell.img = self.picDataArray[indexPath.row];
        }else{
            cell.img = nil;
        }
        return cell;
    }
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    if (collectionView == self.collectionView) {
        if ([self.dataArray[indexPath.row][@"value"] isEqualToString:@"0"]) {
            self.dataArray[indexPath.row][@"value"] = @"1";
        }else{
            self.dataArray[indexPath.row][@"value"] = @"0";
        }
        [self.collectionView reloadData];
    }else{
        if (self.picDataArray.count >= 9) {
            NSLog(@"最多只能上传9张图片");
            ShowMessage(@"最多只能上传9张图片");
        }else{
            [self selectPictures];
        }
    }
}
#pragma mark -- ZYQAssetPickerControllerDelegate
-(void)assetPickerController:(ZYQAssetPickerController *)picker didFinishPickingAssets:(NSArray *)assets{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        for (int i=0; i<assets.count; i++){
            ALAsset *asset = assets[i];
            UIImage *tempImg = [UIImage imageWithCGImage:asset.defaultRepresentation.fullScreenImage];
            
            NSData *dataWithImage;
            //            //判断图片是不是png格式的文件
            //            if (UIImagePNGRepresentation(tempImg)) {
            //                //返回为png图像。
            //                dataWithImage = UIImagePNGRepresentation(tempImg);
            //            }else {
            //返回为JPEG图像。
            dataWithImage = UIImageJPEGRepresentation(tempImg, 0.3);
            //            }
            
            [self.picDataArray addObject:tempImg];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self.picCollectionView reloadData];
            });
        }
    });
}
#pragma mark -- UITextViewDelefate
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@"其他想说的"]) {
        textView.textColor = [UIColor blackColor];
        textView.text = @"";
    }
    return YES;
}
- (BOOL)textViewShouldEndEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@""]) {
        textView.textColor = [UIColor grayColor];
        textView.text = @"其他想说的";;
    }
    return YES;
}
#pragma mark -- dataArray
- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = @[@{@"id":@"1",@"title":@"价格合理",@"value":@"0"}.mutableCopy,
                       @{@"id":@"2",@"title":@"服务周到",@"value":@"0"}.mutableCopy,
                       @{@"id":@"3",@"title":@"准时送达",@"value":@"0"}.mutableCopy,
                       @{@"id":@"4",@"title":@"诙谐幽默",@"value":@"0"}.mutableCopy,
                       ].mutableCopy;
    }
    return _dataArray;
}
- (NSMutableArray *)picDataArray{
    if (!_picDataArray) {
        _picDataArray = @[].mutableCopy;
    }
    return _picDataArray;
}
@end
